﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BattleNet.DataAccess.Extensions;
using Xunit;

namespace BattleNet.DataAccess.UnitTests.Extensions
{
    public class StringExtensionsTests
    {
        private struct NotEnum{}                    

        private enum TestEnum{one,two}

        [Fact]
        public void ToEnum_CalledByEmptyString_ThrowsArgumentNullException()
        {
            Assert.Throws<ArgumentNullException>(() => string.Empty.ToEnum<TestEnum>());
        }

        [Fact]
        public void ToEnum_CalledByWhiteSpace_ThrowsArgumentNullException()
        {
            Assert.Throws<ArgumentNullException>(() => " ".ToEnum<TestEnum>());
        }

        [Fact]
        public void ToEnum_CalledByNull_ThrowsArgumentNullException()
        {
            string nullstring = null;
            Assert.Throws<ArgumentNullException>(() => nullstring.ToEnum<TestEnum>());
        }

        [Fact]
        public void ToEnum_CalledByNonEnumGeneric_ThrowsArgumentNullException()
        {
            Assert.Throws<ArgumentException>(() => "I Exist".ToEnum<NotEnum>());
        }


        [Fact]
        public void ToEnum_RecivedStringWithNoMatchingString_ThrowsArgumentException()
        {
            Assert.Throws<ArgumentException>(() => "Sadly, No Enum Exists For Me".ToEnum<TestEnum>());
        }

        [Fact]
        public void ToEnum_RecivedStringWithMatchingString_ReturnsEnum()
        {
            Assert.Equal(TestEnum.one, "one".ToEnum<TestEnum>());
        }

        [Fact]
        public void ToEnum_RecivedStringWithMatchingStringBadCasing_ReturnsEnum()
        {
            Assert.Equal(TestEnum.two, "TwO".ToEnum<TestEnum>());
        }
    }
}
